package com.sip.dbadapter.dao.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
 *
 */
@Entity
@Table(name = "API_DEFINITION")
public class ApiDefinition implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long apiId;

    private String name;

    private String packageHierachy;

    private Integer scanType;
    
    private String apiStatus="ACTIVE";

    private ScanTypeRest scanTypeRest;

    private ScanTypeWs scanTypeWs;

    private ScanTypeRmi scanTypeRmi;

    private SystemInfo systemInfo;
    
 

	private Set<ConsumeType> consumeTypeSet = new HashSet<ConsumeType>();

    private Set<ProduceType> produceTypeSet = new HashSet<ProduceType>();
    
    private Set<ScenarioRecord> scenarioRecordSet = new HashSet<ScenarioRecord>();

    public ApiDefinition() {
        apiId = Long.valueOf(0);
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "API_ID", unique = true, nullable = false)
    public Long getApiId() {

        return apiId;
    }

    @Column(name = "NAME", nullable = false)
    public String getName() {

        return name;
    }

    @Column(name = "PACKAGE_HIERARCHY", nullable = true)
    public String getPackageHierachy() {

        return packageHierachy;
    }

    @Column(name = "SCAN_TYPE", nullable = false)
    public Integer getScanType() {

        return scanType;
    }
    
   
    @Column(name = "STATUS",  nullable = false) 
    public String getApiStatus() {
    
        return apiStatus;
    }

    public void setScenarioRecordSet(Set<ScenarioRecord> scenarioRecordSet) {
		this.scenarioRecordSet = scenarioRecordSet;
	}
   	
    @JoinColumn(name="API_ID", referencedColumnName="API_ID")
   	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    public Set<ScenarioRecord> getScenarioRecordSet() {
		return scenarioRecordSet;
	}


	@JoinColumn(name="API_ID", referencedColumnName="API_ID")
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)// mappedBy = "apiDefinitionConsumeType"
    public Set<ConsumeType> getConsumeTypeSet() {

        return consumeTypeSet;
    }

	@JoinColumn(name="API_ID", referencedColumnName="API_ID")
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    public Set<ProduceType> getProduceTypeSet() {
        return produceTypeSet;
    }

    
    @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.EAGER)//, orphanRemoval = true
    @PrimaryKeyJoinColumn
    public ScanTypeRest getScanTypeRest() {

        return scanTypeRest;
    }

    // -----------------------------


    //@OneToOne(fetch = FetchType.EAGER, mappedBy = "apiDefinition", cascade = CascadeType.ALL, optional = true)
    
    @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.EAGER)//, orphanRemoval = true
    @PrimaryKeyJoinColumn
    public ScanTypeWs getScanTypeWs() {

        return scanTypeWs;
    }

   
   // @OneToOne(fetch = FetchType.EAGER, mappedBy = "apiDefinition", cascade = CascadeType.ALL, optional = true)
    
    @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.EAGER)//, orphanRemoval = true
    @PrimaryKeyJoinColumn
    public ScanTypeRmi getScanTypeRmi() {

        return scanTypeRmi;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SYSTEM_ID", nullable = true)
    public SystemInfo getSystemInfo() {

        return systemInfo;
    }

    public void setApiId(Long apiId) {

        this.apiId = apiId;
    }

    public void setName(String name) {

        this.name = name;
    }

    public void setPackageHierachy(String packageHierachy) {

        this.packageHierachy = packageHierachy;
    }

    public void setScanType(Integer scanType) {

        this.scanType = scanType;
    }
    

    public void setApiStatus(String apiStatus) {
    
        this.apiStatus = apiStatus;
    }

    public void setConsumeTypeSet(Set<ConsumeType> consumeTypeSet) {


        this.consumeTypeSet = consumeTypeSet;
    }


    public void setProduceTypeSet(Set<ProduceType> produceTypeSet) {
        this.produceTypeSet = produceTypeSet;
    }

    public void setScanTypeRest(ScanTypeRest scanTypeRest) {

        this.scanTypeRest = scanTypeRest;
    }

    public void setScanTypeWs(ScanTypeWs scanTypeWs) {

        this.scanTypeWs = scanTypeWs;
    }

    public void setScanTypeRmi(ScanTypeRmi scanTypeRmi) {

        this.scanTypeRmi = scanTypeRmi;
    }

    public void setSystemInfo(SystemInfo systemInfo) {

        this.systemInfo = systemInfo;
    }

    

    @Override
    public int hashCode() {

        int result = 0;
        result = (int) (31 * result + apiId);
        result = 31 * result + (name != null ? name.hashCode() : 0);

        return result;
    }

    @Override
    public boolean equals(Object other) {

        if (this == other)
            return true;

        if (other == null || (this.getClass() != other.getClass())) {
            return false;
        }

        ApiDefinition definition = (ApiDefinition) other;
        return (this.apiId == definition.apiId) && (this.name != null && name.equals(definition.name));

    }

}